package metalink.admin;

import java.util.ArrayList;
import java.util.Map;
import java.util.Vector;

import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import model.admin.GetCourseListMo;
import vo.BatchDetailsVo;
import vo.mixed.CourseListVo;
import vo.mixed.ProfessorListVo;

import com.opensymphony.xwork2.ActionSupport;

public class GetCourseList extends ActionSupport {
	int course_id;
	ArrayList<CourseListVo> course_list;
	int professor_id;
	private int result;
	HttpSession session;
	
	String value="";
	//------------ Pagination --------------//
	private int page;
	private String morepages;
	private Vector noofpages=new Vector();
	private int nextpage;
	private int currentpage;
	private String hasprevpage;
	private int prevpage;
	private int items;
	//private Vector pagelist=new Vector();
	

	public int getProfessor_id() {
		return professor_id;
	}

	public void setProfessor_id(int professor_id) {
		this.professor_id = professor_id;
	}

	public int getCourse_id() {
		return course_id;
	}

	public void setCourse_id(int course_id) {
		this.course_id = course_id;
	}

	ArrayList<ProfessorListVo> course_professor_list;

	public ArrayList<ProfessorListVo> getCourse_professor_list() {
		return course_professor_list;
	}

	public void setCourse_professor_list(
			ArrayList<ProfessorListVo> course_professor_list) {
		this.course_professor_list = course_professor_list;
	}

	public ArrayList<CourseListVo> getCourse_list() {
		return course_list;
	}

	public void setCourse_list(ArrayList<CourseListVo> course_list) {
		this.course_list = course_list;
	}

	public String execute() {
		ArrayList<ProfessorListVo> pagelist = new ArrayList<ProfessorListVo>();
		GetCourseListMo course_list_object = new GetCourseListMo();
		course_professor_list = new ArrayList<ProfessorListVo>();
		if(value.contentEquals("viewprof")){
			course_professor_list=course_list_object.getCourseProfessorDetails(course_id,0);
		}
		result = course_professor_list.size();
		//---------- Pagination ------------------//
		
		int p=getPage();
        if(p==0)
        {
            setHasprevpage("false");
        }
        else
        {
            setHasprevpage("true");
            setPrevpage(p-1);
        }

        setCurrentpage(p);

        int count;
        count=0;

        int size=course_professor_list.size();
        setItems(size);
        int pagesinlist=size/15;
        while(count<=pagesinlist)
        {
            noofpages.add(count);
            count++;
        }
        count=0;
        while(count<15)
        {

            if(size>=(p*15)+count+1)
            {
                System.out.println(p);
                pagelist.add(course_professor_list.get((p*15)+count));
                System.out.println((p*15)+count);
                System.out.println("size"+pagelist.size());
                count++;
                setMorepages("true");
                setNextpage(p+1);

            }
            else
            {
                setMorepages("false");
                break;
            }
        }
		setCourse_list(course_list_object.getCourseList(0));
		return SUCCESS;
	}
	/*
	public String execute() {
		GetCourseListMo course_list_object = new GetCourseListMo();
		setCourse_list(course_list_object.getCourseList(0));
		
		ArrayList<CourseListVo> pagelist = new ArrayList<CourseListVo>();
		result = course_list_object.getCourseList(0).size();
		session = ServletActionContext.getRequest().getSession();
		session.setAttribute("course_id", course_id);
				//---------- Pagination ------------------//
				
				int p=getPage();
		        if(p==0)
		        {
		            setHasprevpage("false");
		        }
		        else
		        {
		            setHasprevpage("true");
		            setPrevpage(p-1);
		        }

		        setCurrentpage(p);

		        int count;
		        count=0;

		        int size=course_list_object.getCourseList(0).size();
		        setItems(size);
		        int pagesinlist=size/15;
		        while(count<=pagesinlist)
		        {
		            noofpages.add(count);
		            count++;
		        }
		        count=0;
		        while(count<15)
		        {

		            if(size>=(p*15)+count+1)
		            {
		                System.out.println(p);
		                pagelist.add(course_list_object.getCourseList(0).get((p*15)+count));
		                System.out.println((p*15)+count);
		                System.out.println("size"+pagelist.size());
		                count++;
		                setMorepages("true");
		                setNextpage(p+1);

		            }
		            else
		            {
		                setMorepages("false");
		                break;
		            }
		        }
		
		return SUCCESS;
	}

	public String getCourseProfessorDetails() {
		GetCourseListMo courseProfListObj = new GetCourseListMo();
		setCourse_professor_list(courseProfListObj.getCourseProfessorDetails(course_id));
		
		ArrayList<ProfessorListVo> pagelist = new ArrayList<ProfessorListVo>();
		result = courseProfListObj.getCourseProfessorDetails(course_id).size();
		session = ServletActionContext.getRequest().getSession();
		session.setAttribute("course_id", course_id);
				//---------- Pagination ------------------//
				
				int p=getPage();
		        if(p==0)
		        {
		            setHasprevpage("false");
		        }
		        else
		        {
		            setHasprevpage("true");
		            setPrevpage(p-1);
		        }

		        setCurrentpage(p);

		        int count;
		        count=0;

		        int size=courseProfListObj.getCourseProfessorDetails(course_id).size();
		        setItems(size);
		        int pagesinlist=size/15;
		        while(count<=pagesinlist)
		        {
		            noofpages.add(count);
		            count++;
		        }
		        count=0;
		        while(count<15)
		        {

		            if(size>=(p*15)+count+1)
		            {
		                System.out.println(p);
		                pagelist.add(courseProfListObj.getCourseProfessorDetails(course_id).get((p*15)+count));
		                System.out.println((p*15)+count);
		                System.out.println("size"+pagelist.size());
		                count++;
		                setMorepages("true");
		                setNextpage(p+1);

		            }
		            else
		            {
		                setMorepages("false");
		                break;
		            }
		        }
		
		return SUCCESS;
	}

	public String getCourseProfessorCourseDetails() {
		GetCourseListMo courseProfCourseListObj = new GetCourseListMo();
		setCourse_list(courseProfCourseListObj.getCourseList(professor_id));
		
		ArrayList<CourseListVo> pagelist = new ArrayList<CourseListVo>();
		result = courseProfCourseListObj.getCourseList(professor_id).size();
		session = ServletActionContext.getRequest().getSession();
		session.setAttribute("professor_id", professor_id);
				//---------- Pagination ------------------//
				
				int p=getPage();
		        if(p==0)
		        {
		            setHasprevpage("false");
		        }
		        else
		        {
		            setHasprevpage("true");
		            setPrevpage(p-1);
		        }

		        setCurrentpage(p);

		        int count;
		        count=0;

		        int size=courseProfCourseListObj.getCourseList(professor_id).size();
		        setItems(size);
		        int pagesinlist=size/15;
		        while(count<=pagesinlist)
		        {
		            noofpages.add(count);
		            count++;
		        }
		        count=0;
		        while(count<15)
		        {

		            if(size>=(p*15)+count+1)
		            {
		                System.out.println(p);
		                pagelist.add(courseProfCourseListObj.getCourseList(professor_id).get((p*15)+count));
		                System.out.println((p*15)+count);
		                System.out.println("size"+pagelist.size());
		                count++;
		                setMorepages("true");
		                setNextpage(p+1);

		            }
		            else
		            {
		                setMorepages("false");
		                break;
		            }
		        }
		
		return SUCCESS;
	}
*/
	public int getResult() {
		return result;
	}

	public void setResult(int result) {
		this.result = result;
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public String getMorepages() {
		return morepages;
	}

	public void setMorepages(String morepages) {
		this.morepages = morepages;
	}

	public Vector getNoofpages() {
		return noofpages;
	}

	public void setNoofpages(Vector noofpages) {
		this.noofpages = noofpages;
	}

	public int getNextpage() {
		return nextpage;
	}

	public void setNextpage(int nextpage) {
		this.nextpage = nextpage;
	}

	public int getCurrentpage() {
		return currentpage;
	}

	public void setCurrentpage(int currentpage) {
		this.currentpage = currentpage;
	}

	public String getHasprevpage() {
		return hasprevpage;
	}

	public void setHasprevpage(String hasprevpage) {
		this.hasprevpage = hasprevpage;
	}

	public int getPrevpage() {
		return prevpage;
	}

	public void setPrevpage(int prevpage) {
		this.prevpage = prevpage;
	}

	public int getItems() {
		return items;
	}

	public void setItems(int items) {
		this.items = items;
	}
/*
	public ArrayList<CourseListVo> getPagelist() {
		return pagelist;
	}

	public void setPagelist(ArrayList<CourseListVo> pagelist) {
		this.pagelist = pagelist;
	}
	*/

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}
}
